class_name MagicComponent
extends Node

signal magic_changed(current_magic: float, max_magic: float)



@export var max_magic: float = 1
var _current_magic: float
var current_magic: float:
	get:
		return _current_magic
	set(value):
		_current_magic = value
		magic_changed.emit(_current_magic, max_magic)




func _ready() -> void:
	current_magic = max_magic


func spend(amount: float) -> bool:
	if current_magic - amount < 0.0:
		return false
	current_magic = clamp(current_magic - amount, 0.0, max_magic)
	return true


func reset_magic(context_max_magic: float) -> void:
	max_magic = context_max_magic
	current_magic = max_magic
